package com.controller;

import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.entity.Cartltem;
import com.service.CartService;


@Controller
public class CartController {
	@Resource
	private CartService cs;
	@Resource
	private HttpServletRequest request;
	@RequestMapping("cart")
	public String cart(Cartltem cart){
		String pid=request.getParameter("id");
		int product_id=Integer.parseInt(pid);//获取商品id
		
		HttpSession session=request.getSession();
		int order_id=(int) session.getAttribute("order_id");//获取订单id
		
		cs.updateCart(product_id, order_id, cart);
		List<Cartltem> list =cs.finall(order_id);
		session.setAttribute("list", list);
		return "/productPage?page=1";
	}
	@RequestMapping("pushOneCart")
	public String pushOneCart(Cartltem cart){
		String pid=request.getParameter("id");
		int product_id=Integer.parseInt(pid);//获取商品id
		
		HttpSession session=request.getSession();
		int order_id=(int) session.getAttribute("order_id");//获取订单id
		
		cs.updateCart(product_id, order_id, cart);
		return "/finOrder";
	}
	@RequestMapping("subOneCart")
	public String subOne(Model model){
		String pid=request.getParameter("id");
		int product_id=Integer.parseInt(pid);//获取商品id
		
		HttpSession session=request.getSession();
		int order_id=(int) session.getAttribute("order_id");//获取订单id
		cs.subOneCart(product_id, order_id);
		return "/finOrder";
	}
}
